﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for MyBasePage
/// </summary>
public class MyBasePage : System.Web.UI.Page
{
    public MyBasePage()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public string myTheme = "Main";

    protected override void OnPreInit(EventArgs e)
    {
        base.OnPreInit(e);
        this.Theme = myTheme;
    }


    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        ChangeURL();
        //Logout();
    }

    public bool requireSSL = false;

    void ChangeURL()
    {
        if (requireSSL && !Request.IsSecureConnection)//if(requireSSL&&(Request.IsSecureConnection==false))
        {
            string url = Request.Url.ToString().Replace("http://", "https://").Replace("localhost:555/", "localhost:443/");
            Response.Redirect(url);
        }
        if (!requireSSL && Request.IsSecureConnection)//if (!requireSSL && (Request.IsSecureConnection==true))
        {
            string url = Request.Url.ToString().Replace("https://", "http://").Replace("localhost:443/", "localhost:555/").Replace("localhost/", "localhost:555/");
            Response.Redirect(url);
        }
    }

    public bool CheckSession()
    {
        if (Session["uid"] == null)
        {
            //(sender as Page).Response.Redirect("Default.aspx");
            Response.Write("<script>alert('Please Login!');window.parent.location='Default.aspx'</script>");
            
            return false;
        }
        //(sender as Page).Response.Write("<script>alert(window.parent);window.location='Default.aspx'</script>");
        return true;
    }
}
